#ifndef SERIALCLIENT_H
#define SERIALCLIENT_H

#include <QObject>
#include <QSerialPort>
#include <QSerialPortInfo>
#include "prase.h"
class SerialClient : public QObject
{
    Q_OBJECT
public:
    explicit SerialClient(QObject *parent = nullptr);

    QStringList getAllSerialPort();

    bool openSerialPort(QString portName,int rate,int datalen,int checklen,int stoplen);

    void disConnectSerialPort();

    void sendData(QByteArray);

    void clearCache(){
        m_cache.clear();
        m_size = 0;
    }
signals:
    void signReadyRead(QString );

    void signPrase(PowerInfo);

    void signPrase(GPSInfo);

    void signPrase(CommunicationInfo);

    void signCPBJPrase();

    void signRecvData(QByteArray ,bool);
private slots:

    void readyRead();

    void error(QSerialPort::SerialPortError serialPortError);
private:
    QSerialPort     m_serialPort;
    QString         m_portName;
    int             m_rate;
    int             m_datalen;
    int             m_checklen;
    int             m_stoplen;

    Prase           m_praser;
    char *          m_data;
    QByteArray      m_cache;
    int             m_size = 0;
    QString         m_orderName;
};

#endif // SERIALCLIENT_H
